package com.sccba.web.controller.yjcz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sccba.common.annotation.Log;
import com.sccba.common.core.controller.BaseController;
import com.sccba.common.core.domain.AjaxResult;
import com.sccba.common.core.page.TableDataInfo;
import com.sccba.common.enums.BusinessType;
import com.sccba.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sccba.emtbusiness.domain.YjczProductEventDetail;
import com.sccba.emtbusiness.service.IYjczProductEventDetailService;

/**
 * 生产事件补录Controller
 * 
 * @author lichh
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/yjcz/productEventDetail")
public class YjczProductEventDetailController extends BaseController
{
    @Autowired
    private IYjczProductEventDetailService yjczProductEventDetailService;

    /**
     * 查询生产事件补录列表
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEventDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjczProductEventDetail yjczProductEventDetail)
    {
        startPage();
        List<YjczProductEventDetail> list = yjczProductEventDetailService.selectYjczProductEventDetailList(yjczProductEventDetail);
        return getDataTable(list);
    }

    /**
     * 导出生产事件补录列表
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEventDetail:export')")
    @Log(title = "生产事件补录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjczProductEventDetail yjczProductEventDetail)
    {
        List<YjczProductEventDetail> list = yjczProductEventDetailService.selectYjczProductEventDetailList(yjczProductEventDetail);
        ExcelUtil<YjczProductEventDetail> util = new ExcelUtil<YjczProductEventDetail>(YjczProductEventDetail.class);
        util.exportExcel(response, list, "生产事件补录数据");
    }

    /**
     * 获取生产事件补录详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEventDetail:query')")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(yjczProductEventDetailService.selectYjczProductEventDetailByPkId(pkId));
    }

    /**
     * 新增生产事件补录
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEventDetail:add')")
    @Log(title = "生产事件补录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjczProductEventDetail yjczProductEventDetail)
    {
        return toAjax(yjczProductEventDetailService.insertYjczProductEventDetail(yjczProductEventDetail));
    }

    /**
     * 修改生产事件补录
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEventDetail:edit')")
    @Log(title = "生产事件补录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjczProductEventDetail yjczProductEventDetail)
    {
        return toAjax(yjczProductEventDetailService.updateYjczProductEventDetail(yjczProductEventDetail));
    }

    /**
     * 删除生产事件补录
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEventDetail:remove')")
    @Log(title = "生产事件补录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds)
    {
        return toAjax(yjczProductEventDetailService.deleteYjczProductEventDetailByPkIds(pkIds));
    }

    @GetMapping(value = "/queryDetailByEventId/{eventId}")
    public AjaxResult queryDetailByEventId(@PathVariable("eventId") Long eventId)
    {
        return success(yjczProductEventDetailService.selectDetailByEventId(eventId));
    }

    @PostMapping(value = "/submitEventDetail")
    public AjaxResult submitEventDetail (@RequestBody YjczProductEventDetail productEventDetail) {
        yjczProductEventDetailService.submitProductEventDetail(productEventDetail);
        return success();
    }
}
